package com.xigua.JucOfBeautiful.chapterTwo._指令重排序2_10;

/**
 * @author LiRongHua
 * @Title: ${file_name}
 * @Package ${package_name}
 * @Description: ${todo}
 * @date 2022/1/2423:37
 */
public  class ReadThread extends Thread {

    private static volatile   int num = 0;
    private static volatile   boolean ready = false;

    @Override
    public void run() {
        while (!Thread.currentThread().isInterrupted()){
            if (ready){
                System.out.println(num+num);
            }
            System.out.println(num);
        }
    }

    public static class Writethread extends Thread{
        @Override
        public void run() {
            ready = true;
            num = 2;
        }
    }

    public static void main(String[] args) throws InterruptedException {
        ReadThread readThread = new ReadThread();
        readThread.start();

        Writethread writethread = new Writethread();
        writethread.start();

        Thread.sleep(1);
        readThread.interrupt();
        System.out.println("main exit");

    }


}
